package com.example.eldersystem.operatedata.mapper;

import com.example.eldersystem.operatedata.model.Event;
import org.apache.ibatis.annotations.*;
import java.util.List;


public interface EventMapper {

    @Insert("insert into event_info(event_type,event_date,event_location,event_desc,oldperson_id,volunteer_id) " +
            "values (#{eventType},#{eventDate},#{eventLocation},#{eventDescription},#{oldPersonId},#{volunteerId}) ")
    int addEvent(Event event);


    @Update("update event_info " +
            "set event_type=#{eventType}," +
            "event_date=#{eventDate}," +
            "event_location=#{eventLocation}," +
            "event_desc=#{eventDescription}," +
            "oldperson_id=#{oldPersonId}," +
            "volunteer_id=#{volunteerId}" +
            "where id = #{id}")
    int updateEvent(Event event);

    @Delete("delete from event_info where id = #{id}")
    int deleteEvent(int id);

    @Select("select count(*) from event_info")
    int selectEventNum();

    @Select("select event_info.id,event_type,event_date,event_location,event_desc,oldperson_info.username,volunteer_info.name "+
            "from event_info "+
            "left join oldperson_info on event_info.oldperson_id=oldperson_info.id "+
            "left join volunteer_info on volunteer_info.id=event_info.volunteer_id")
    @Results(id="select1",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "eventType",column = "event_Type"),
            @Result(property = "eventDate",column = "event_date"),
            @Result(property = "eventLocation",column = "event_location"),
            @Result(property = "eventDescription",column = "event_desc"),
            @Result(property = "oldPersonName",column = "username"),
            @Result(property = "volunteerName",column = "name"),
    })
    List<Event> selectEvent();
}
